<template>
  <view class="my-picker-container">
    <wd-search
      v-model="localValue"
      :placeholder="props.placeholder"
      placeholder-left
      hide-cancel
      @change="handleInput"
    />
  </view>
</template>

<script setup lang="ts">
import { ref } from 'vue'

const props = defineProps({
  label: {
    type: String,
  },

  modelValue: {
    type: String,
    default: '',
  },

  placeholder: {
    type: String,
    default: '请输入单号',
  },
})

const emit = defineEmits(['confirm'])

const localValue = ref(props.modelValue) // 中转变量

watch(
  () => props.modelValue,
  (newVal) => {
    localValue.value = newVal
  },
)

let throttle: any = null
// 输入框修改时触发
const handleInput = (value: string) => {
  //节流
  if (throttle) {
    clearTimeout(throttle)
  }
  throttle = setTimeout(() => {
    emit('confirm', value)
  }, 500)
}
</script>

<style scoped></style>
